package demo7.musicBox;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
@Data
public class MusicBox {
    List<Play> songList = null;
    public MusicBox(){
        songList = createSongList();
        currentNumber=0;
    }
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Song {
        private String name;
        private String author;
    }
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Play{
        private Song song;
        private int number;
    }
    private int currentNumber;
    // play , next , back ,  song loop
    // voice
    // song list
    public List<Play> createSongList() {
        return Lists.newArrayList(
                new Play(new Song("A", "hcj"),1),
                new Play(new Song("B", "hcj1"),2),
                new Play(new Song("C", "hcj2"),3));
    }

    public void play(int number) {
        if(number<0 ){
            throw new RuntimeException("not exist!!!");
        }
        if(number>songList.size()){
            stop();
        }
        Play play = songList.get(number);
        Song song = play.getSong();
        System.out.println("play current song"+song+" , the  number is :"+number);
    }
    public void stop(){}
    public void current(){
        play(currentNumber);
    }
    public void next() {
        play(currentNumber+1);
    }

    public void back() {
        play(currentNumber-1);
    }

    public void choose(int number) {
        play(number);
    }

    public void run(){
        play(currentNumber);
    }
}
